import os
import time

from PIL import Image

from ScrapyObject.spiders.utils.bb import na


def batch_tga_to_png(tga_folder, png_folder):
    os.makedirs(png_folder, exist_ok=True)
    for filename in os.listdir(tga_folder):
        if filename.lower().endswith('.tga'):
            tga_path = os.path.join(tga_folder, filename)
            png_path = os.path.join(png_folder, filename[:-4] + '.png')
            try:
                with Image.open(tga_path) as img:
                    img.save(png_path, format='PNG')
            except Exception as e:
                print(f"❌ 失败: {filename}, 错误: {e}")

if __name__ == '__main__':
    print('开始')
    timestamp = int(time.time())

    batch_tga_to_png("C:\\2\\" + na, "C:\\4")

    endTime = int(time.time())
    print(str(endTime - timestamp))
    print('结束')
